package com.hxzy.boot.old.responsecontroller;

import com.hxzy.boot.pojo.Result;
import com.hxzy.boot.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wzm
 * @create 2023-09-25 9:29
 * project_name:javaweb2308
 */

@RestController
public class RespController05 {

    //1.响应字符串到浏览器
    @RequestMapping("/str001")
    public Result str(){

        return new Result(1,null,"Hello");
    }

    //2.响应实体对象
    @RequestMapping("/user001")
    public Result user(){
        //对象
        User user = new User();
        user.setName("张三");
        user.setAge(15);
        user.setAddress("昆明");
        return Result.success(user);
    }

    //3.响应java集合
    @RequestMapping("/list001")
    public Result list(){
        //对象
        User user = new User();
        user.setName("张三");
        user.setAge(15);
        user.setAddress("昆明");

        //对象
        User user1 = new User();
        user1.setName("李四");
        user1.setAge(18);
        user1.setAddress("昆明");

        List<User> list = new ArrayList<>();
        list.add(user);
        list.add(user1);

        return Result.success(list);
    }


}
